/*
 * FeeBO.java
 *
 * Created on March 28, 2007, 6:59 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.jjenkins.data;

/**
 * This class has all the setters and getters needed for the attributes
 * @author Josh
 */
public class FeeBO extends RevenueSourceBO{
    
    private double amount;
    private RentalBO rental;
    private EmployeeBO employee;
    
    /** Creates a new instance of FeeBO */
    public FeeBO() {
    }
    
    /**
     * Gets the amount
     * @return double
     */
    public double getAmount() {
        return amount;
    }
    
    /**
     * Sets the amount
     * @param amount double
     */
    public void setAmount(double amount) {
        this.amount = amount;
    }
    
    /**
     * Gets the rentalBO
     * @return RentalBO
     */
    public RentalBO getRental() {
        return rental;
    }
    
    /**
     * Sets the rentalBO
     * @param rental RentalBO
     */
    public void setRental(RevenueSourceBO rental) {
        this.rental = (RentalBO)rental;
    }
    
    /**
     * Gets the EmployeeBO
     * @return EmployeeBO
     */
    public EmployeeBO getEmployee() {
        return employee;
    }
    
    /**
     * Sets the employeeBO
     * @param employee EmployeeBO
     */
    public void setEmployee(EmployeeBO employee) {
        this.employee = employee;
    }
    
    /**
     * Calculates and returns the price
     * @return double
     */
    public double calcPrice(){
        int  numDays = 0;
        double lateFeePerDay = 0;
        try{
            String physicalID = rental.getForRent().getId();
            String conceptualID = ((PhysicalBO)PhysicalDAO.getInstance().read(physicalID)).getConceptual().getId();
            lateFeePerDay = ((ConceptualRentalBO)ConceptualRentalDAO.getInstance().read(conceptualID)).getLateFeePerDay();
            numDays = rental.calcDaysOverdue();
        }catch(DataException e){
            e.printStackTrace();
        }
        
        this.setPrice((double)numDays * lateFeePerDay);
        return (double)numDays * lateFeePerDay;
    }
    
    /**
     * Creates and returns a description
     * @return String
     */
    public String createDescription(){
        String fullDescription = null;
        try{
            String physicalID = rental.getForRent().getId();
            String concRentID = ((PhysicalBO)PhysicalDAO.getInstance().read(physicalID)).getConceptual().getId();
            String description = ConceptualRentalDAO.getInstance().read(concRentID).getDescription();
            fullDescription = "Late fee - " + description + " (" + rental.calcDaysOverdue() + " days overdue)";
        }catch (DataException e){
            e.printStackTrace();
        }
        return fullDescription;
    }
}
